package youcaihuaoa.weetop.com.ui.main

import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.listener.OnItemClickListener
import com.gyf.immersionbar.ImmersionBar
import com.robot.base.base.activity.GLBaseActivity
import com.robot.base.configs.AppConstants
import youcaihuaoa.weetop.com.BR
import youcaihuaoa.weetop.com.R
import youcaihuaoa.weetop.com.databinding.AppActivityNotifyMessageBinding
import youcaihuaoa.weetop.com.ui.adapter.NotifyItemAdapter
import youcaihuaoa.weetop.com.vm.main.NotifyMessageViewModel

@Route(path = AppConstants.Router.Main.A_NOTIFY_MESSAGE)
class NotifyMessageActivity :
    GLBaseActivity<AppActivityNotifyMessageBinding, NotifyMessageViewModel>() {

    private lateinit var notifyItemAdapter: NotifyItemAdapter

    override fun initComponents() {
        ImmersionBar.with(this).fitsSystemWindows(false).init()
        notifyItemAdapter = NotifyItemAdapter().apply {
            setOnItemClickListener { adapter, view, position ->
                if (notifyItemAdapter.data[position].status != "1")
                    viewModel.userMessageNoticeEdit("1", notifyItemAdapter.data[position].id ?: "")
            }

        }
        binding.recyclerView.apply {
            layoutManager = LinearLayoutManager(this@NotifyMessageActivity)
            adapter = notifyItemAdapter
        }
        viewModel.getUserMessageNotice()
    }

    override fun initContentView(savedInstanceState: Bundle?): Int =
        R.layout.app_activity_notify_message

    override fun initVariableId(): Int = BR.viewModel

    override fun initViewObservable() {
        super.initViewObservable()
        viewModel.uiChangeEvent.dataEvent.observe(this) {
            notifyItemAdapter.setList(it)
        }
    }
}